package com.zeildx.glife.view;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

import com.zeildx.glife.GetAdapter;
import com.zeildx.glife.R;
import com.zeildx.glife.entity.Word;
import com.zeildx.glife.getViewModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link getAllFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class getAllFragment extends Fragment {
//    Button buttonInsert,buttonClear;
    getViewModel getViewModel;
//    RecyclerView recyclerView;
//    GetAdapter getAdapter1,getAdapter2;
//    Switch aSwitch;
//    LiveData<List<Word>>allWordsLive;
    private NavController navController;

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

//    private Object AppCompatActivity;

    public getAllFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment getAllFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static getAllFragment newInstance(String param1, String param2) {
        getAllFragment fragment = new getAllFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }

        //ViewModelProviders.of(this).get(getViewModel.class);

        //allWordsLive = wordDao.getAllWordsLive();


//        textView = (TextView) getView().findViewById(R.id.textView);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_get_all, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
//        navController = Navigation.findNavController(requireActivity().findViewById(R.id.fragment));
//        NavigationUI.setupActionBarWithNavController(this,navController);
//        NavigationUI.setupWithNavController(bottomNavigationView,navController);

//        recyclerView = requireActivity().findViewById(R.id.recyclerView);
//        getAdapter1 = new GetAdapter(false);
//        getAdapter2 = new GetAdapter(true);
//        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
//        recyclerView.setAdapter(getAdapter1);
//        aSwitch = requireActivity().findViewById(R.id.switch1);
//        aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
//                if(b){
//                    recyclerView.setAdapter(getAdapter2);
//                }else {
//                    recyclerView.setAdapter(getAdapter1);
//                }
//            }
//        });
//
//        getViewModel = ViewModelProviders.of(this).get(getViewModel.class);
//
//        getViewModel.getAllWordsLive().observe(getViewLifecycleOwner(), new Observer<List<Word>>() {
//            @Override
//            public void onChanged(List<Word> words) {
//
//                getAdapter1.setAllGetWords(words);
//                getAdapter2.setAllGetWords(words);
//                getAdapter1.notifyDataSetChanged();
//                getAdapter2.notifyDataSetChanged();
//            }
//        });
//
//        buttonInsert = requireActivity().findViewById(R.id.buttonInsert);;
//        buttonClear = requireActivity().findViewById(R.id.buttonClear);
//
//        buttonInsert.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                String[] date = {
//                        "9月1号",
//                        "9月2号",
//                        "9月3号",
//                        "9月4号",
//                        "9月5号",
//                        "9月6号",
//                        "9月7号",
//                };
//                String[] schedule = {
//                        "读书",
//                        "看报",
//                        "看电影",
//                        "去图书馆",
//                        "打游戏",
//                        "敲代码",
//                        "开学",
//                };
//                for(int i = 0;i<date.length;i++){
//                    getViewModel.insertWords(new Word(date[i],schedule[i]));
//                }
//
//            }
//        });
//
//        buttonClear.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                getViewModel.deleteAllWords();
//
//            }
//        });

    }
}